Evaluation

Why evaluate an entire RAG system rather than just its language model?


  • A working RAG application can still retrieve irrelevant documents, fabricate answers, respond slowly, or cost too much.
  • Evaluate data preparation → chunking → embeddings → vector index → retrieval/reranking → prompt → generation together: poor context can make a strong model produce poor answers.
  • Define success using business requirements: factual accuracy, groundedness, useful responses, latency, cost, safety, and any domain-specific rules.
  • Change one component at a time, rerun the same evaluation cases, and compare quality, speed, and cost before adopting a change.

Which metrics measure retrieval and answer quality?


  • Context precision: How much of the retrieved content is relevant, particularly near the top of the results?
  • Context recall: Did retrieval find the information needed to answer the question?
  • Context relevance: Does the supplied context actually relate to the user’s question?
  • Faithfulness/groundedness: Are the answer’s claims supported by the retrieved context rather than invented?
  • Answer relevancy: Does the response address the user’s question?
  • Answer correctness: Is the response factually right compared with a trusted reference answer?
  • Performance/cost: Measure end-to-end and retrieval latency, token usage, model or serving cost, and failure rates.
  • High answer quality does not prove retrieval quality: a model may answer from prior knowledge despite retrieving irrelevant passages.

How do human feedback and LLM judges work together?


  • Explicit feedback: Users or subject-matter experts rate responses, flag errors, or supply corrections.
  • Implicit feedback: Signals such as repeated questions, reformulations, or abandoned sessions can suggest problems but are ambiguous.
  • LLM-as-a-judge: A separate model scores responses against criteria such as groundedness, relevance, helpfulness, or a custom rubric.
  • Built-in scorers assess common qualities; guideline-based or custom scorers encode business requirements; code-based scorers enforce deterministic rules (for example, required JSON keys or prohibited fields).
  • LLM judges can make mistakes or vary between runs. Calibrate them against human-reviewed examples, especially for sensitive or high-stakes decisions.
  • Keep evaluation active after deployment: monitor new traces and feedback, investigate regressions, and update tests when requirements change.

How do you prepare a useful evaluation dataset?


  • Create representative test cases containing a request and, when possible, a trusted expected_response or reference facts.
  • Include common questions, ambiguous requests, missing-information cases, multi-document questions, and questions the system should decline to answer.
  • Include cases where retrieved data is stale, irrelevant, or contradictory to test whether the model stays grounded.
  • Treat each row like a regression test; keep a stable baseline set and add new cases from production failures.
  • Example dataset structure:
import pandas as pd

eval_data = pd.DataFrame([
    {
        "request": "What is the return policy for damaged products?",
        "expected_response": "Use the verified policy wording from your source documents."
    },
    {
        "request": "Which products support Bluetooth?",
        "expected_response": "List only products confirmed by the product catalog."
    },
])
  • Replace placeholder expected responses with actual verified answers before using correctness scores.

How do you evaluate a registered Databricks RAG application with MLflow?


  • Find the registered RAG model in Catalog Explorer → Models, and note its fully qualified name (catalog.schema.model) and version.
  • Load or reference the registered model version; prepare evaluation rows with request and expected_response as required by the course’s evaluation interface.
  • The course demonstrates the legacy Agent Framework approach using mlflow.evaluate(..., model_type="databricks-agent") and make_genai_metric_from_prompt for a custom creativity judge. These APIs are version-dependent; newer MLflow GenAI evaluation workflows use mlflow.genai.evaluate and scorers instead.
  • A conceptual example of the course’s legacy workflow (adapt the model URI, evaluation schema, and metric configuration to the installed MLflow version):
import mlflow

model_uri = "models:/dbacademy.get_started_genai.YOUR_RAG_MODEL/1"

# Legacy Agent Framework example; available APIs depend on MLflow version.
results = mlflow.evaluate(
    model=model_uri,
    data=eval_data,
    model_type="databricks-agent",
)

print(results.metrics)
  • For a custom judge, define a clear rubric and test its scores against human-reviewed examples; the lesson’s make_genai_metric_from_prompt is part of the older GenAI metric interface.
  • Inspect MLflow Evaluation Results, Model Metrics, individual outputs, and traces. Aggregate scores reveal trends; individual failures explain what to fix.
  • Preserve the registered model and evaluation artifacts because subsequent lessons may reuse them.

How should you use evaluation results to improve a RAG application?


  • Low context recall: Revisit chunk boundaries, embedding choice, indexing coverage, search filters, and retrieval k.
  • Low context precision: Improve search queries, metadata filtering, hybrid search, or reranking.
  • Low faithfulness: Tighten instructions to use retrieved evidence, add citations, and require an admission when evidence is missing.
  • Low answer correctness: Inspect both the retrieved evidence and generation; compare against a verified reference answer.
  • High latency or cost: Reduce unnecessary retrieval, context size, model calls, or expensive model usage, then check that quality remains acceptable.
  • Track changes across versions and continuously score representative production traffic, subject to privacy and governance requirements.

Where is the current documentation?